package com.treasure.mall.biz.service.core.user;

import com.treasure.mall.biz.base.SearchableCrudService;
import com.treasure.mall.biz.dto.condition.MerchantSearchCondition;
import com.treasure.mall.biz.dto.user.ModifyBalanceDTO;
import com.treasure.mall.biz.dto.user.ModifyDepositDTO;
import com.treasure.mall.biz.dto.user.ModifyShopDTO;
import com.treasure.mall.biz.entity.embeddable.ReceivingInfo;
import com.treasure.mall.biz.entity.user.DepositLogPO;
import com.treasure.mall.biz.entity.user.MerchantPO;
import com.treasure.mall.biz.vo.user.ApplyMerchantVO;
import com.treasure.mall.biz.vo.user.MerchantVO;
import com.treasure.mall.zbq.common.exception.ApiException;
import com.treasure.mall.zbq.common.ienum.live.LiveEnums;
import org.springframework.data.domain.Page;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/6/11
 */
public interface MerchantService extends SearchableCrudService<MerchantPO, Long>, UserDetailsService {


    /**
     * 发起余额修改，未做金额是否超出判断，需调用方自行判断，并记录日志
     *
     * @param modifyBalanceDTO {@link com.treasure.mall.biz.dto.user.ModifyBalanceDTO}
     */
    void modifyBalance(ModifyBalanceDTO modifyBalanceDTO);

    /**
     * 修改用户待入账余额
     *
     * @param modifyBalanceDTO
     */
    void modifyBalanceInFuture(ModifyBalanceDTO modifyBalanceDTO);

    /**
     * 分页
     *
     * @param pageIndex
     * @param pageSize
     * @param condition
     * @return
     */
    Page<MerchantPO> findAll(int pageIndex, int pageSize, MerchantSearchCondition condition);


    /**
     * 提交开店申请数据
     *
     * @param userId
     * @param dto
     */
    MerchantPO applyShop(Long userId, ModifyShopDTO dto);

    /**
     * 修改店铺信息
     *
     * @param userId
     * @param dto
     */
    void modifyShopData(Long userId, ModifyShopDTO dto);

    /**
     * 获取当前用户申请店铺数据
     * 必须已支付了，才能获取到数据
     *
     * @param userId
     * @return
     */
    ApplyMerchantVO findApplyShopDataByUserId(Long userId);

    /**
     * 根据商家ID获取店铺数据
     *
     * @param merchantId 商家ID
     * @param userId     用户ID
     * @return
     */
    MerchantVO findShopDataByMerchantId(Long merchantId, Long userId);

    /**
     * 修改店铺申请
     *
     * @param id          申请ID
     * @param auditStatus 审核状态
     * @param reason      审核理由
     * @return
     */
    boolean modifyAuditStatus(Long id, LiveEnums.AuditStatus auditStatus, String reason);

    List<MerchantVO> listVO(List<MerchantPO> pos, Long userId);

    /**
     * 货款转正
     *
     * @param merchantId
     * @param amount
     * @param subOrderId
     */
    @Transactional
    void settlePayment(Long merchantId, BigDecimal amount, String subOrderId);

    void resetPassword(Long merchantId);

    void changePassword(String origin, String newPass);

    /**
     * 修改商户主营类目
     *
     * @param merchantId
     * @param categoryId
     */
    void modifyMainCategory(Long merchantId, Long categoryId);

    boolean checkExistByCategoryId(Long categoryId);

    /**
     * 修改商家保证金
     *
     * @param dto {@link ModifyDepositDTO}
     */
    @Transactional(noRollbackFor = ApiException.class)
    void modifyDeposit(ModifyDepositDTO dto);

    /**
     * 保证金日志
     *
     * @param merchantId
     * @param pageIndex
     * @param pageSize
     * @return
     */
    Page<DepositLogPO> depositLogs(Long merchantId, int pageIndex, int pageSize);

    void toggleContactStatus(Long id);

    /**
     * 修改商户退货地址
     *
     * @param merchantId
     * @param receivingInfo
     */
    void updateReturnedPurchaseAddress(Long merchantId, ReceivingInfo receivingInfo);


    @Transactional
    void setRewardRate(Long merchantId, BigDecimal rate, BigDecimal rebateRateOne, BigDecimal rebateRateTwo);

    boolean exists(Long merchantId);
}